#!/bin/bash

print_usage ()
{
    echo "Usage $0 <imei file list> <clientfile>"
    echo ""
    echo "Look for client file containing the list of IMEI"
    echo "and print the associated key if found."
}

imeilist=$1
clientfile=$2

if [ "x$clientfile" = "x" ]; then
    print_usage
    exit 1
fi

if [ ! -f $clientfile ]; then
    echo "Client file >$clientfile< doesn't exists. Aborting ..."
    exit 1
fi

if [ ! -f $imeilist ]; then
    echo "IMEI List file >$imeilist< doesn't exists. Aborting ..."
    exit 1
fi

for i in `cat $imeilist`
do

  unlockline=`grep $i $clientfile`

  if [ $? -ne 0 ]; then
      echo "$i    ...   KO"
      continue
  fi

  echo "$unlockline"

done
